package com.sansecy.base;

public class FileSizeUtil {
    public static String capacity(double size) {
        String capacity = "B";
        double output = 0;

        if (size / 1024 > 1) {
            output = size / 1024;
            capacity = "KB";
        }
        if (size / 1024 / 1024 > 1) {
            output = size / 1024 / 1024;
            capacity = "MB";
        }
        if (size / 1024 / 1024 / 1024 > 1) {
            output = size / 1024 / 1024 / 1024;
            capacity = "GB";
        }
        if (size / 1024 / 1024 / 1024 / 1024 > 1) {
            output = size / 1024 / 1024 / 1024 / 1024;
            capacity = "TB";
        }
        if (output == 0) {
            return 0 + capacity;
        }
        return NumberUtil.doubleFormat(output) + capacity;
    }

    public static String capacityUnit(long size) {
        if (size < 1024) {
            return "B";
        } else if (size < 1024 * 1024) {
            return "KB";
        } else if (size < 1024 * 1024 * 1024) {
            return "MB";
        } else if (size < 1024 * 1024 * 1024 * 1024) {
            return "GB";
        } else if (size < 1024 * 1024 * 1024 * 1024 * 1024) {
            return "TB";
        }
        return "";
    }
}
